package com.penghk.hangzhouhouseprice.controller;

import com.penghk.hangzhouhouseprice.service.GanjiNewHousePriceService;
import com.penghk.hangzhouhouseprice.service.GanjiSecondHousePriceService;
import com.penghk.hangzhouhouseprice.service.LianjiaAreaPriceService;
import com.penghk.hangzhouhouseprice.service.LianjiaHousePriceService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Enumeration;

/**
 * @author penghk
 * 拉取网络房价数据
 */
@RestController
public class CrawlerController {

   @Autowired
   GanjiNewHousePriceService ganjiHousePriceService;

   @Autowired
   GanjiSecondHousePriceService ganjiSecondHousePriceService;

   @Autowired
   LianjiaAreaPriceService lianjiaAreaPriceService;

   @Autowired
    LianjiaHousePriceService lianjiaHousePriceService;

    @ApiOperation(value="获取赶集网新房房价数据", notes="")
    @RequestMapping("/start0")
    public String startGanji() {
        return ganjiHousePriceService.getHousePrice();
    }

    @ApiOperation(value = "获取赶集网二手房价信息")
    @RequestMapping("/start1")
    public String startGanjiSecond() {
        return ganjiSecondHousePriceService.getHousePrice();
    }

    @ApiOperation(value = "获取链家杭州区域二手房价信息")
    @RequestMapping("/start2")
    public String startLianjia() {
        return lianjiaAreaPriceService.getHousePrice();
    }

    @ApiOperation(value = "获取链家杭州所有区域二手房价信息")
    @RequestMapping("/start3")
    public String getAllhousePrice() {
        lianjiaHousePriceService.saveFromNet();
        return "";
    }

    @ApiOperation(value = "获取session")
    @RequestMapping("/session")
    public void getSession(HttpServletRequest request) {
        Enumeration<String> headers =  request.getHeaderNames();
        request.getServletContext();
        HttpSession session = request.getSession();
        String id = session.getId();
        long creationTime = session.getCreationTime();
        session.setAttribute("name" , "tony");
        long acctime = session.getLastAccessedTime();
        int interval = session.getMaxInactiveInterval();//默认 1800s 30分钟
        System.out.println(id+" "+creationTime+" "+acctime+" "+interval);
        session.setMaxInactiveInterval(5);
    }



}
